package cn.tedu.icop.finance.dao.repository.impl;

import cn.tedu.icop.finance.dao.repository.CostRuleCacheRepository;
import cn.tedu.icop.finance.pojo.po.CostRulePO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.ValueOperations;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public class CostRuleCacheRepositoryImpl implements CostRuleCacheRepository {

    @Autowired
    private RedisTemplate redisTemplate;


    @Override
    public List<CostRulePO> getCostRuleByStationId(Integer stationId) {
        ValueOperations<String, List<CostRulePO>> valueOperations = redisTemplate.opsForValue();
        String costRuleKey = "COST_RULE_KEY_" + stationId;
        return valueOperations.get(costRuleKey);
    }

    @Override
    public void saveCostRule(Integer stationId, List<CostRulePO> dbCostRules) {
        ValueOperations<String, List<CostRulePO>> valueOperations = redisTemplate.opsForValue();
        String costRuleKey = "COST_RULE_KEY_" + stationId;
        valueOperations.set(costRuleKey, dbCostRules);
    }
}
